<?php

namespace App\Http\Controllers\Seller;

use App\Http\Requests\SellerProfileRequest;
use App\Models\User;
use Auth;
use Hash;

class ProfileController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $user = Auth::user();
        $addresses = $user->addresses;
        $bankName = [
            ['14000f001' => 'BANGKOK BANK PUBLIC COMPANY LTD.'],
            ['14000f002' => 'BANK FOR AGRICULTURE AND AGRICULTURAL CO-OPERATIVES'],
            ['14000f001' => 'BANGKOK BANK PUBLIC COMPANY LTD.'],
            ['14000f002' => 'BANK FOR AGRICULTURE AND AGRICULTURAL CO-OPERATIVES'],
            ['14000f003' => 'BANK OF AYUDHYA'],
            ['14000f004' => 'Bank of China'],
            ['14000f005' => 'CIMB (THAI) PUBLIC COMPANY LIMITED'],
            ['14000f006' => 'CITIBANK, N.A. (CITI), BANGKOK BRANCH'],
            ['14000f007' => 'DEUTSCHE BANK AKTIENGESELLSCHAFT (DB)'],
            ['14000f008' => 'GOVERNMENT HOUSING BANK'],
            ['14000f009' => 'GOVERNMENT SAVING BANK'],
            ['14000f010' => 'HONGKONG and SHANGHAI CORPORATION LTD.'],
            ['14000f011' => 'INDUSTRIAL AND COMMERCIAL BANK OF CHAINA (THAI)'],
            ['14000f012' => 'ISLAMIC BANK OF THAILAND (ISBT)'],
            ['14000f013' => 'KASIKORNBANK PUBLIC COMPANY LIMITED'],
            ['14000f014' => 'KIATNAKIN PHATRA BANK PUBLIC COMPANY LIMITED'],
            ['14000f015' => 'KRUNG THAI BANK PUBLIC COMPANY LTD.'],
            ['14000f016' => 'LAND AND HOUSES RETAIL BANK PUBLIC COMPANY LIMITED'],
            ['14000f017' => 'SIAM COMMERCIAL BANK PUBLIC COMPANY LTD.'],
            ['14000f018' => 'STANDARD CHARTERED BANK (THAI) PUBLIC COMPANY LTD.'],
            ['14000f019' => 'SUMITOMO MITSUI BANKING CORPORATION (SMBC)'],
            ['14000f020' => 'THAI CREDIT RETAIL BANK PUBLIC COMPANY LIMITED (TCRB)'],
            ['14000f021' => 'THANACHART BANK PUBLIC COMPANY LIMITED'],
            ['14000f022' => 'THE GOVERNMENT SAVING BANK'],
            ['14000f023' => 'TISCO BANK PUBLIC COMPANY LIMITED'],
            ['14000f024' => 'TMB BANK PUBLIC COMPANY LIMITED'],
            ['14000f025' => 'UNITED OVERSEAS BANK (THAI) PUBLIC COMPANY LIMITED'],
            ['22000f001'=>'Akbank'],
            ['22000f002'=>'Aktif Bank'],
            ['22000f003'=>'Albaraka'],
            ['22000f004'=>'Anadolubank'],
            ['22000f005'=>'Denizbank'],
            ['22000f006'=>'En Para'],
            ['22000f007'=>'Finans bank'],
            ['22000f008'=>'Garanti Bankası'],
            ['22000f009'=>'Halk Bankası'],
            ['22000f010'=>'HSBC Bank'],
            ['22000f011'=>'INGBank'],
            ['22000f012'=>'İş Bankası'],
            ['22000f013'=>'Koop Bank'],
            ['22000f014'=>'Kuveyttürk'],
            ['22000f015'=>'PTT'],
            ['22000f016'=>'QNB Finansbank'],
            ['22000f017'=>'Şekerbank'],
            ['22000f018'=>'TEB Bankası'],
            ['22000f019'=>'Türk Ekonomi Bankası'],
            ['22000f020'=>'Türk Eximbank'],
            ['22000f021'=>'Türkiye Finans Bank'],
            ['22000f022'=>'Türkiye iş Bankası'],
            ['22000f023'=>'Turkland Bank'],
            ['22000f024'=>'Vakıfbank'],
            ['22000f025'=>'Yapı Kredi'],
            ['22000f026'=>'Ziraat Bankası'],
            ['19000f001'=>'ABC CAPITAL'],
            ['19000f002'=>'ACCENDO BANCO'],
            ['19000f003'=>'ACTINVER'],
            ['19000f004'=>'AFIRME'],
            ['19000f005'=>'AKALA'],
            ['19000f006'=>'AMERICAN EXPRES'],
            ['19000f007'=>'ASP INTEGRA OPC'],
            ['19000f008'=>'AUTOFIN'],
            ['19000f009'=>'AZTECA'],
            ['19000f010'=>'BAJIO'],
            ['19000f011'=>'BANAMEX'],
            ['19000f012'=>'BANCO FINTERRA'],
            ['19000f013'=>'BANCO S3'],
            ['19000f014'=>'BANCOMEXT'],
            ['19000f015'=>'BANCOPPEL'],
            ['19000f016'=>'BANCREA'],
            ['19000f017'=>'BANJERCITO'],
            ['19000f018'=>'BANK OF AMERICA'],
            ['19000f019'=>'BANKAOOL'],
            ['19000f020'=>'BANOBRAS'],
            ['19000f021'=>'BANORTE'],
            ['19000f022'=>'BANREGIO'],
            ['19000f023'=>'BANSEFI'],
            ['19000f024'=>'BANSI'],
            ['19000f025'=>'BANXICO'],
            ['19000f026'=>'BARCLAYS'],
            ['19000f027'=>'BBASE'],
            ['19000f028'=>'BBVA BANCOMER'],
            ['19000f029'=>'BMONEX'],
            ['19000f030'=>'CAJA POP MEXICA'],
            ['19000f031'=>'CAJA TELEFONIST'],
            ['19000f032'=>'CB INTERCAM'],
            ['19000f033'=>'CI BOLSA'],
            ['19000f034'=>'CIBANCO'],
            ['19000f035'=>'CLS'],
            ['19000f036'=>'CoDi Valida'],
            ['19000f037'=>'COMPARTAMOS'],
            ['19000f038'=>'CONSUBANCO'],
            ['19000f039'=>'CREDICAPITAL'],
            ['19000f040'=>'CREDIT SUISSE'],
            ['19000f041'=>'CRISTOBAL COLON'],
            ['19000f042'=>'DEUTSCHE'],
            ['19000f043'=>'DONDE'],
            ['19000f044'=>'ESTRUCTURADORES'],
            ['19000f045'=>'EVERCORE'],
            ['19000f046'=>'FINAMEX'],
            ['19000f047'=>'FINCOMUN'],
            ['19000f048'=>'FOMPED'],
            ['19000f049'=>'FONDO (FIRA)'],
            ['19000f050'=>'GBM'],
            ['19000f051'=>'HDI SEGUROS'],
            ['19000f052'=>'HIPOTECARIA FED'],
            ['19000f053'=>'HSBC'],
            ['19000f054'=>'ICBC'],
            ['19000f055'=>'INBURSA'],
            ['19000f056'=>'INDEVAL'],
            ['19000f057'=>'INMOBILIARIO'],
            ['19000f058'=>'INTERCAM BANCO'],
            ['19000f059'=>'INVERCAP'],
            ['19000f060'=>'INVEX'],
            ['19000f061'=>'JP MORGAN'],
            ['19000f062'=>'KUSPIT'],
            ['19000f063'=>'LIBERTAD'],
            ['19000f064'=>'MASARI'],
            ['19000f065'=>'MIFEL'],
            ['19000f066'=>'MIZUHO BANK'],
            ['19000f067'=>'MONEXCB'],
            ['19000f068'=>'MUFG'],
            ['19000f069'=>'MULTIVA BANCO'],
            ['19000f070'=>'MULTIVA CBOLSA'],
            ['19000f071'=>'NAFIN'],
            ['19000f072'=>'PAGATODO'],
            ['19000f073'=>'PROFUTURO'],
            ['19000f074'=>'REFORMA'],
            ['19000f075'=>'SABADELL'],
            ['19000f076'=>'SANTANDER'],
            ['19000f077'=>'SCOTIABANK'],
            ['19000f078'=>'SHINHAN'],
            ['19000f079'=>'STP'],
            ['19000f080'=>'TRANSFER'],
            ['19000f081'=>'UNAGRA'],
            ['19000f082'=>'VALMEX'],
            ['19000f083'=>'VALUE'],
            ['19000f084'=>'VE POR MAS'],
            ['19000f085'=>'VECTOR'],
            ['19000f086'=>'VOLKSWAGEN'],
            ['MANDIRI'=>'MANDIRI'],
            ['BRI'=>'BANK BRI'],
            ['BNI'=>'BANK BNI'],
            ['BCA'=>'BANK BCA'],
            ['BANK_UOB'=>'BANK UOB INDONESIA'],
            ['BRI_SYR'=>'BANK BRI SYARIAH'],
            ['DANAMON'=>'BANK DANAMON'],
            ['MANDIRI_SYR'=>'BANK SYARIAH MANDIRI'],
            ['PERMATA'=>'PERMATA BANK'],
            ['MAYBANK'=>'BANK MAYBANK'],
            ['PANIN'=>'BANK PANIN'],
            ['CIMB'=>'BANK CIMB NIAGA'],
            ['ARTA_NIAGA_KENCANA'=>'BANK ARTA NIAGA KENCANA'],
            ['BANK_BUANA'=>'BANK BUANA IND'],
            ['BANK_LIPPO'=>'BANK LIPPO'],
            ['OCBC'=>'BANK NISP'],
            ['CITIBANK'=>'CITIBANK'],
            ['JPMORGAN'=>'JP. MORGAN CHASE BANK'],
            ['BAML'=>'BANK OF AMERICA'],
            ['BANK_ING'=>'ING INDONESIA BANK'],
            ['BANK_MUL'=>'BANK MULTICOR TBK.'],
            ['ARTHA'=>'BANK ARTHA GRAHA'],
            ['BANK_C_AGR'=>'BANK CREDIT AGRICOLE INDOSUEZ'],
            ['BANK_COMP'=>'THE BANGKOK BANK COMP. LTD'],
            ['BANK_TOKYO'=>'THE BANK OF TOKYO MITSUBISHI UFJ LTD'],
            ['MITSUI'=>'BANK SUMITOMO MITSUI INDONESIA'],
            ['DBS'=>'BANK DBS INDONESIA'],
            ['RESONA'=>'BANK RESONA PERDANIA'],
            ['MIZUHO'=>'BANK MIZUHO INDONESIA'],
            ['STANDARD_CHARTERED'=>'STANDARD CHARTERED BANK'],
            ['BANK_ABN'=>'BANK ABN AMRO'],
            ['BANK_KEPPEL'=>'BANK KEPPEL TATLEE BUANA'],
            ['CAPITAL'=>'BANK CAPITAL INDONESIA, TBK.'],
            ['BNP_PARIBAS'=>'BANK BNP PARIBAS INDONESIA'],
            ['BANK_DANAMON'=>'KOREA EXCHANGE BANK DANAMON'],
            ['RABOBANK'=>'RABOBANK INTERNASIONAL INDONESIA'],
            ['PANIN'=>'ANZ PANIN BANK'],
            ['DEUTSCHE'=>'DEUTSCHE BANK AG.'],
            ['BANK_WOOR'=>'BANK WOORI INDONESIA'],
            ['BOC'=>'BANK OF CHINA LIMITED'],
            ['BUMI_ARTA'=>'BANK BUMI ARTA'],
            ['KESEJAHTERAAN_EKONOMI'=>'BANK EKONOMI'],
            ['BANK_ANTAR'=>'BANK ANTARDAERAH'],
            ['BANK_HAGA'=>'BANK HAGA'],
            ['BANK_IFI'=>'BANK IFI'],
            ['MAYAPADA'=>'BANK MAYAPADA'],
            ['DKI'=>'BANK DKI'],
            ['DAERAH_ISTIMEWA'=>'BPD DIY'],
            ['BANK_JATENG'=>'BANK JATENG'],
            ['BANK_JATIM'=>'BANK JATIM'],
            ['JAMBI'=>'BPD JAMBI'],
            ['ACEH'=>'BPD ACEH'],
            ['SUMUT'=>'BANK SUMUT'],
            ['BANK_NAGARI'=>'BANK NAGARI'],
            ['RIAU_DAN_KEPRI'=>'BANK RIAU'],
            ['SUMSEL_DAN_BABEL'=>'BANK SUMSEL'],
            ['LAMPUNG'=>'BANK LAMPUNG'],
            ['BPD_KALSEL'=>'BPD KALSEL'],
            ['KALIMANTAN_BARAT'=>'BPD KALIMANTAN BARAT'],
            ['BPD_KAITIM'=>'BPD KALTIM'],
            ['BPD_KALTENG'=>'BPD KALTENG'],
            ['SULSELBAR'=>'BPD SULSEL'],
            ['SUMSEL_DAN_BABEL'=>'BANK SULUT'],
            ['BPD_NTB'=>'BPD NTB'],
            ['BALI'=>'BPD BALI'],
            ['BANK_NTT'=>'BANK NTT'],
            ['MALUKU'=>'BANK MALUKU'],
            ['PAPUA'=>'BPD PAPUA'],
            ['BENGKULU'=>'BANK BENGKULU'],
            ['SULAWESI'=>'BPD SULAWESI TENGAH'],
            ['BANK_SULTRA'=>'BANK SULTRA'],
            ['NUSANTARA_PARAHYANGAN'=>'BANK NUSANTARA PARAHYANGAN'],
            ['BANK_SWADESI'=>'BANK SWADESI'],
            ['MUAMALAT'=>'BANK MUAMALAT'],
            ['MESTIKA_DHARMA'=>'BANK MESTIKA'],
            ['SHINHAN'=>'BANK METRO EXPRESS'],
            ['MASPION'=>'BANK MASPION'],
            ['BANK_HAGAKITA'=>'BANK HAGAKITA'],
            ['GANESHA'=>'BANK GANESHA'],
            ['CCB'=>'BANK WINDU KENTJANA'],
            ['BANK_HARM'=>'BANK HARMONI INTERNATIONAL'],
            ['QNB_INDONESIA'=>'BANK KESAWAN'],
            ['BTN'=>'BANK TABUNGAN NEGARA (PERSERO)'],
            ['BANK_HIM'=>'BANK HIMPUNAN SAUDARA 1906, TBK.'],
            ['TABUNGAN_PENSIUNAN_NASIONAL'=>'BANK TABUNGAN PENSIUNAN NASIONAL'],
            ['BANK_SWAGUNA'=>'BANK SWAGUNA'],
            ['MEGA'=>'BANK MEGA'],
            ['BUKOPIN'=>'BANK BUKOPIN'],
            ['BISNIS_INTERNASIONAL'=>'BANK BISNIS INTERNASIONAL'],
            ['JASA_JAKARTA'=>'BANK JASA JAKARTA'],
            ['BANK_BUMIPUTERA'=>'BANK BUMIPUTERA'],
            ['BANK_YUDHA'=>'BANK YUDHA BHAKTI'],
            ['BANK_MITRAN'=>'BANK MITRANIAGA'],
            ['AGRONIAGA'=>'BANK AGRO NIAGA'],
            ['BANK_INDOMONEX'=>'BANK INDOMONEX'],
            ['ROYAL'=>'BANK ROYAL INDONESIA'],
            ['MEGA_SYR'=>'BANK SYARIAH MEGA'],
            ['BANK_INA'=>'BANK INA PERDANA'],
            ['PRIMA_MASTER'=>'PRIMA MASTER BANK'],
            ['BANK_PERSY'=>'BANK PERSYARIKATAN INDONESIA'],
            ['BANK_AKITA'=>'BANK AKITA'],
            ['BANK_NOBU'=>'BANK DIPO INTERNATIONAL'],
            ['NATIONALNOBU'=>'BANK NOBU'],
            ['KESEJAHTERAAN_EKONOMI'=>'BANK KESEJAHTERAAN EKONOMI'],
            ['ARTOS'=>'BANK ARTOS IND'],
            ['BTPN_SYARIAH'=>'BANK PURBA DANARTA'],
            ['MULTI_ARTA_SENTOSA'=>'BANK MULTI ARTA SENTOSA'],
            ['MAYORA'=>'BANK MAYORA'],
            ['INDEX_SELINDO'=>'BANK INDEX SELINDO'],
            ['BANK_VICTORIA'=>'BANK VICTORIA INTERNATIONAL'],
            ['BANK_EKSEK'=>'BANK EKSEKUTIF'],
            ['CENTRATAMA'=>'CENTRATAMA NASIONAL BANK'],
            ['FAMA'=>'BANK FAMA INTERNASIONAL'],
            ['MANDIRI_TASPEN'=>'BANK SINAR HARAPAN BALI'],
            ['HARDA_INTERNASIONAL'=>'BANK HARDA'],
            ['BANK_FINCONESIA'=>'BANK FINCONESIA'],
            ['BANK_MERIN'=>'BANK MERINCORP'],
            ['BANK_MAYBANK'=>'BANK MAYBANK INDOCORP'],
            ['OCBC'=>'BANK OCBC - INDONESIA'],
            ['CHINATRUST'=>'BANK CHINA TRUST INDONESIA'],
            ['COMMONWEALTH'=>'BANK COMMONWEALTH'],
            ['BJB_SYR'=>'BJB SYARIAH'],
            ['BCA_SYR'=>'BANK BCA SYARIAH'],
            ['BNI_SYR'=>'BANK BNI SYARIAH'],
            ['OKE'=>'BANK ANDARA'],
            ['PANIN_SYR'=>'BANK PANIN DUBAI SYARIAH'],
            ['HSBC'=>'BANK HSBC'],
            ['SINARMAS_UUS'=>'BANK SINARMAS'],
            ['BANK_JABAR'=>'BANK JABAR BANTEN'],
            ['DINAR_INDONESIA'=>'BANK DINAR INDONESIA'],
            ['HANA'=>'BANK HANA'],
            ['ICBC'=>'BANK ICBC'],
            ['JTRUST'=>'BANK JTRUST'],
            ['EXIMBANK'=>'BANK EKSPOR INDONESIA'],
            ['12000f001'=>'ABBANK'],
            ['12000f002'=>'AGRIBANK'],
            ['12000f003'=>'BIDV BANK'],
            ['12000f004'=>'BVB'],
            ['12000f005'=>'CBBANK'],
            ['12000f006'=>'CIMB'],
            ['12000f007'=>'DBS'],
            ['12000f008'=>'DongABank'],
            ['12000f009'=>'EXIMBANK'],
            ['12000f010'=>'GP BANK'],
            ['12000f011'=>'HD BANK'],
            ['12000f012'=>'HSBC'],
            ['12000f013'=>'IVB'],
            ['12000f014'=>'KIEN LONG BANK'],
            ['12000f015'=>'LienVietPostBank（LPB）'],
            ['12000f016'=>'MARITIME BANK（MSB）'],
            ['12000f017'=>'MBBANK'],
            ['12000f018'=>'NAMA BANK'],
            ['12000f019'=>'NCB'],
            ['12000f020'=>'NGAN HANG A CHAU'],
            ['12000f021'=>'OCEANBANK'],
            ['12000f022'=>'PBVN'],
            ['12000f023'=>'PGBANK'],
            ['12000f024'=>'PHUONGDONG BANK'],
            ['12000f025'=>'PVCOMBANK'],
            ['12000f026'=>'SACOMBANK'],
            ['12000f027'=>'SAIGONBANK'],
            ['12000f028'=>'SCB'],
            ['12000f029'=>'SEABANK'],
            ['12000f030'=>'SHB BANK'],
            ['12000f031'=>'TECHCOMBANK'],
            ['12000f032'=>'TIENPHONG BANK'],
            ['12000f033'=>'VAB BANK'],
            ['12000f034'=>'VIB BANK'],
            ['12000f035'=>'VIET CAPITAL BANK'],
            ['12000f036'=>'VIETBANK'],
            ['12000f037'=>'VIETCOMBANK'],
            ['12000f038'=>'VIETINBANK'],
            ['12000f039'=>'VPBANK'],
            ['12000f040'=>'VRB'],
            ['12000f041'=>'WOORI'],
            ['16000f001'=>'Affin Bank'],
            ['16000f002'=>'AGRO'],
            ['16000f003'=>'Alliance Bank Malaysia Berhad'],
            ['16000f004'=>'AmBank'],
            ['16000f005'=>'Bank Islam Malaysia'],
            ['16000f006'=>'Bank Muamalate'],
            ['16000f007'=>'Bank Rakyat'],
            ['16000f008'=>'BSN'],
            ['16000f009'=>'CIMB Bank'],
            ['16000f010'=>'Hong Leong Bank'],
            ['16000f011'=>'HSBC'],
            ['16000f012'=>'Maybank'],
            ['16000f013'=>'OCBC'],
            ['16000f014'=>'Public Bank Berhad'],
            ['16000f015'=>'RHB Bank'],
            ['16000f016'=>'UOB'],
        ];
        $usdt_type_arr=["TRC-20","ERC-20"];
        return view('seller.profile.index', compact('user','addresses','bankName','usdt_type_arr'));
    }
    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(SellerProfileRequest $request , $id)
    {
        if(env('DEMO_MODE') == 'On'){
            flash(translate('Sorry! the action is not permitted in demo '))->error();
            return back();
        }

        $user = User::findOrFail($id);
        $user->name = $request->name;
        $user->phone = $request->phone;

        if($request->new_password != null && ($request->new_password == $request->confirm_password)){
            $user->password = Hash::make($request->new_password);
        }

        $user->avatar_original = $request->photo;

        $shop = $user->shop;


        if($shop){
            $shop->cash_on_delivery_status = $request->cash_on_delivery_status;
            $shop->bank_payment_status = $request->bank_payment_status;
            $shop->bank_name = $request->bank_name;
            $shop->bank_acc_name = $request->bank_acc_name;
            $shop->bank_acc_no = $request->bank_acc_no;
            $shop->bank_routing_no = $request->bank_routing_no;
            $shop->usdt_address = $request->usdt_address;
            $shop->usdt_payment_status = $request->usdt_payment_status;
            $shop->usdt_type = $request->usdt_type;
//            $shop->online_ervice = $request->online_ervice;
            $shop->save();
        }

        $user->save();

        flash(translate('Your Profile has been updated successfully!'))->success();
        return back();
    }
    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function online_service_update(SellerProfileRequest $request , $id)
    {
        if(env('DEMO_MODE') == 'On'){
            flash(translate('Sorry! the action is not permitted in demo '))->error();
            return back();
        }

        $user = User::findOrFail($id);
        $shop = $user->shop;
        if($shop){
            $shop->online_ervice = $request->online_ervice;
            $shop->save();
        }
        $user->save();

        flash(translate('Online Service has been updated successfully!'))->success();
        return back();
    }
}
